//
//  ASColCollectionCell.swift
//  soapp
//
//  Created by zhu xietong on 2018/4/24.
//

import Foundation
import UIKit
import AsyncDisplayKit

extension ASSizeRange{
    public static func collectionNode(collectionNode:ASCollectionNode,indexPath:IndexPath,controller:UIViewController?=nil)->ASSizeRange{
        if let data = collectionNode.cellData(at: indexPath)
        {
            guard let NodeType = ASCollectionNode.cellNodeType(data: data, indexPath: indexPath, selector: collectionNode.cell_selector!) else{
                print("can not get NodeType for model:\(data)")
                fatalError()
            }
            let cellNode = NodeType.init()
            if let sizeCell = cellNode as? ASSizeRangeCell{
                sizeCell.isSizeCalculateCell = true
                sizeCell.mo.controller = controller
                sizeCell.mo.model = data
                return sizeCell.sizeRange()
            }
        }
        return ASSizeRangeCell().sizeRange()

    }
}
open class ASSizeRangeCell: JoCellNode {
    
    public var isSizeCalculateCell = false//用来标记size计算型cell 不执行mo_model_reload
    
 
    open override var mo:MoAtrribute{
        get{
            if let _mo = __extention["MoAtrributeInstance"] as? MoAtrribute{
                _mo.ower = self
                if isSizeCalculateCell{
                    _mo.needReload = false
                }else{
                    _mo.needReload = true
                }
                return _mo
                
            }
            let _mo = MoAtrribute()
            if isSizeCalculateCell{
                _mo.needReload = false
            }else{
                _mo.needReload = true
            }
            __extention["MoAtrributeInstance"] = _mo
            _mo.ower = self
            return _mo
        }
        set{
            newValue.ower = self
            __extention["MoAtrributeInstance"] = newValue
            
            self.mo_model_willSet(new: newValue.model)
            self.mo_detail_willSet(new: newValue.detail)
            if isSizeCalculateCell{
                newValue.needReload = false
            }else{
                newValue.needReload = true
                self.mo_model_reload()
            }
            
        }
    }
    
    open func sizeRange()->ASSizeRange{
    
        return ASSizeRange(min: CGSize(width: Swidth, height: 0), max: CGSize(width: Swidth, height: 10000))
    
    }
}
